{{template "admin/header.html"}}
<script type="text/javascript" src="{{basePath}}admin/js/sha3.min.js"></script>
<title>更新用户 - GPRESS</title>
{{template "admin/bodystart.html"}}



<section class="section">
	<input type="hidden" id="chainType" value="{{.Data.ChainType}}">
	<div class="container">
		<div class="table-content">
			<div class="column">
				<form id="gpress-form" action="{{basePath}}admin/{{.UrlPathParam}}/update" method="POST">
					<ul class="save-ul">
						<li>
							<div class="left">
								ID
							</div>
							<div class="right">
								<input type="hidden" name="id" id="id" value="{{.Data.Id}}" />
								<input class="input is-small" type="text" disabled value="{{.Data.Id}}">
							</div>
						</li>
						<li>
							<div class="left">
								账号
							</div>
							<div class="right">
								<input class="input is-small" type="text" name="account" value="{{.Data.Account}}" id="account">
							</div>
						</li>
						<li>
							<div class="left">
								密码
							</div>
							<div class="right">
								<input class="input is-small" type="password" name="password" value="" id="password">
							</div>
						</li>
						<li>
							<div class="left">
								用户名
							</div>
							<div class="right">
								<input class="input is-small" type="text" name=userName value="{{.Data.UserName}}" id="userName">
							</div>
						</li>
						<li>
							<div class="left">
								区块链类型
							</div>
							<div class="select is-small">
								<select id="chainSelect">
									<option value="">请选择</option>
									<option value="ETH">以太坊</option>
									<option value="XUPER">百度超级链</option>
								</select>
							</div>
						</li>
						<li>
							<div class="left">
								区块链地址
							</div>
							<div class="right">
								<input class="input is-small" type="text" name="chainAddress" value="{{.Data.ChainAddress}}"
									id="chainAddress">
							</div>
						</li>
						
					</ul>

					<div class="field is-grouped" style="padding-left: 190px;">
						<div class="control">
							<button type="submit" class="button is-success is-small">提交</button>
						</div>
						<div class="control">
							<button type="reset" class="button is-info is-light is-small">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</section>

<script>
	let chainType = $('#chainType').val()
	$('#chainSelect').val(chainType)
	$('#chainSelect').change(function(e) {
		chainType = $('#chainSelect').val()
	})
	
	const form = document.getElementById('gpress-form')
	form.addEventListener('submit', async event => {
		event.preventDefault()
		let pwdValue=$('#password').val()
		if(pwdValue&&pwdValue!=""){
			$('#password').val(sha3_512(pwdValue))
		}
		

		const formData = new FormData(form)
		const jsonObject = {}
		for (const [key, value] of formData.entries()) {
			const fieldType = document.querySelector(key)
							jsonObject[key] = value
		}
		jsonObject.sortNo = jsonObject.sortNo-0
		jsonObject.status = jsonObject.status-0
		let key = $('#rsaPublicKey').val()
		let keyVal = { value: JSON.parse('"' + key + '"') }
		jsonObject['rsaPublicKey'] = keyVal.value
		jsonObject.chainType = chainType
		const response = await fetch(form.action, {
			method: form.method,
			body: JSON.stringify(jsonObject),
			headers: { 'Content-Type': 'application/json', }
		})

		let res = await response.json()
		if (res.statusCode == 1) {
			$.confirm({
				useBootstrap: false,
				boxWidth: '400px',
				title: '提示',
				content: '修改成功！',
				type: 'green',
				buttons: {
					'确定': function() {
						//window.location.href = '{{basePath}}admin/{{.UrlPathParam}}/list'
					}
				}
			})
		}
	})
</script>





{{template "admin/bodyend.html"}}
